package boundarys;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;

import ccrm.BoundryControl;
import controllers.UserController;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JLabel;

import entitys.Session;

import java.awt.Font;
import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.io.IOException;

public class MMGUI extends AbstractGUI{

	private JFrame frmCcrmMM;
	private String userid;
	private String userpw;
	

	/**
	 * Create the application.
	 */
	public MMGUI(String userid, String userpw) {
		this.userid = userid;
		this.userpw = userpw;
		initialize();
		initGUI(frmCcrmMM);
		frmCcrmMM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{297, 232, 293, 0};
		gridBagLayout.rowHeights = new int[]{80, 42, 42, 42, 42, 42, 42, 73, 42, 41, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
		frmCcrmMM.getContentPane().setLayout(gridBagLayout);
		
		JLabel lblMarketingManagerPanel = new JLabel("Marketing Manager Panel");
		lblMarketingManagerPanel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 15));
		GridBagConstraints gbc_lblMarketingManagerPanel = new GridBagConstraints();
		gbc_lblMarketingManagerPanel.fill = GridBagConstraints.BOTH;
		gbc_lblMarketingManagerPanel.insets = new Insets(0, 0, 5, 5);
		gbc_lblMarketingManagerPanel.gridx = 1;
		gbc_lblMarketingManagerPanel.gridy = 0;
		frmCcrmMM.getContentPane().add(lblMarketingManagerPanel, gbc_lblMarketingManagerPanel);
		
		JButton ProduceReportBtn = new JButton("Produce Report");
		ProduceReportBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					new ProduceReportGUI();
				}
			}
		});
		
		JButton ManageSalesBtn = new JButton("Manage Sales");
		ManageSalesBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					new ManageSalesGUI();
				}
			}
		});
		
		JButton MaintainResidetialAreaBtn = new JButton("Maintain Residential Area");
		MaintainResidetialAreaBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					new MaintainingResidentialAreaGUI();
				}
			}
		});
		
		JButton ManageProductCategoryTypeBtn = new JButton("Manage Product Category/Type");
		ManageProductCategoryTypeBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					new ManageProductCategoryTypeGUI();
				}
			}
		});
		GridBagConstraints gbc_ManageProductCategoryTypeBtn = new GridBagConstraints();
		gbc_ManageProductCategoryTypeBtn.fill = GridBagConstraints.BOTH;
		gbc_ManageProductCategoryTypeBtn.insets = new Insets(0, 0, 5, 5);
		gbc_ManageProductCategoryTypeBtn.gridx = 1;
		gbc_ManageProductCategoryTypeBtn.gridy = 2;
		frmCcrmMM.getContentPane().add(ManageProductCategoryTypeBtn, gbc_ManageProductCategoryTypeBtn);
		GridBagConstraints gbc_MaintainResidetialAreaBtn = new GridBagConstraints();
		gbc_MaintainResidetialAreaBtn.fill = GridBagConstraints.BOTH;
		gbc_MaintainResidetialAreaBtn.insets = new Insets(0, 0, 5, 5);
		gbc_MaintainResidetialAreaBtn.gridx = 1;
		gbc_MaintainResidetialAreaBtn.gridy = 3;
		frmCcrmMM.getContentPane().add(MaintainResidetialAreaBtn, gbc_MaintainResidetialAreaBtn);
		GridBagConstraints gbc_ManageSalesBtn = new GridBagConstraints();
		gbc_ManageSalesBtn.fill = GridBagConstraints.BOTH;
		gbc_ManageSalesBtn.insets = new Insets(0, 0, 5, 5);
		gbc_ManageSalesBtn.gridx = 1;
		gbc_ManageSalesBtn.gridy = 4;
		frmCcrmMM.getContentPane().add(ManageSalesBtn, gbc_ManageSalesBtn);
		GridBagConstraints gbc_ProduceReportBtn = new GridBagConstraints();
		gbc_ProduceReportBtn.fill = GridBagConstraints.BOTH;
		gbc_ProduceReportBtn.insets = new Insets(0, 0, 5, 5);
		gbc_ProduceReportBtn.gridx = 1;
		gbc_ProduceReportBtn.gridy = 5;
		frmCcrmMM.getContentPane().add(ProduceReportBtn, gbc_ProduceReportBtn);
		
		JButton logOut = new JButton("Log Out");
		logOut.setForeground(Color.RED);
		logOut.setFont(new Font("Tahoma", Font.BOLD, 11));
		logOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(BoundryControl.GUIArr.size()==getIndex()+1)
				{
					goBack();
					UserController.LogoutUser(getUserid(), getUserpw());
				}
			}
		});
		GridBagConstraints gbc_logOut = new GridBagConstraints();
		gbc_logOut.insets = new Insets(0, 0, 5, 5);
		gbc_logOut.fill = GridBagConstraints.BOTH;
		gbc_logOut.gridx = 0;
		gbc_logOut.gridy = 8;
		frmCcrmMM.getContentPane().add(logOut, gbc_logOut);
		frmCcrmMM.setVisible(true);
	}

	public String getUserpw() {
		return userpw;
	}

	public void setUserpw(String userpw) {
		this.userpw = userpw;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmCcrmMM = new JFrame();
		frmCcrmMM.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				UserController.LogoutUser(getUserid(), getUserpw());
			}
		});
		frmCcrmMM.setResizable(false);
		frmCcrmMM.setTitle("CCRM>Marketing Manager Management");
		frmCcrmMM.setBounds(100, 100, 454, 428);
		frmCcrmMM.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	@Override
	public void getReply(Object r) {
		// TODO Auto-generated method stub

		
	}
}
